﻿/**  版本信息模板在安装目录下，可自行修改。
* BDDATATABLE.cs
*
* 功 能： N/A
* 类 名： BDDATATABLE
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/8/8 20:07:22   N/A    初版
*
* Copyright (c) 2012 DQYT.HTDZ Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;
namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDDATATABLE
	/// </summary>
	public partial class BDDATATABLEDAL:IBDDATATABLE
	{
		public BDDATATABLEDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal TABLE_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDDATATABLE");
			strSql.Append(" where TABLE_ID=:TABLE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,22)			};
			parameters[0].Value = TABLE_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(DQYT.HTDZ.Model.BDDATATABLEModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDDATATABLE(");
			strSql.Append("TABLE_ID,TABLE_CODE,TABLE_NAME,DESCTRIPTION)");
			strSql.Append(" values (");
			strSql.Append(":TABLE_ID,:TABLE_CODE,:TABLE_NAME,:DESCTRIPTION)");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,18),
					new OracleParameter(":TABLE_CODE", OracleType.VarChar,30),
					new OracleParameter(":TABLE_NAME", OracleType.VarChar,30),
					new OracleParameter(":DESCTRIPTION", OracleType.VarChar,300)};
			parameters[0].Value = model.TABLE_ID;
			parameters[1].Value = model.TABLE_CODE;
			parameters[2].Value = model.TABLE_NAME;
			parameters[3].Value = model.DESCTRIPTION;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DQYT.HTDZ.Model.BDDATATABLEModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDDATATABLE set ");
			strSql.Append("TABLE_CODE=:TABLE_CODE,");
			strSql.Append("TABLE_NAME=:TABLE_NAME,");
			strSql.Append("DESCTRIPTION=:DESCTRIPTION");
			strSql.Append(" where TABLE_ID=:TABLE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_CODE", OracleType.VarChar,30),
					new OracleParameter(":TABLE_NAME", OracleType.VarChar,30),
					new OracleParameter(":DESCTRIPTION", OracleType.VarChar,300),
					new OracleParameter(":TABLE_ID", OracleType.Number,18)};
			parameters[0].Value = model.TABLE_CODE;
			parameters[1].Value = model.TABLE_NAME;
			parameters[2].Value = model.DESCTRIPTION;
			parameters[3].Value = model.TABLE_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal TABLE_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDATATABLE ");
			strSql.Append(" where TABLE_ID=:TABLE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,22)			};
			parameters[0].Value = TABLE_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string TABLE_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDATATABLE ");
			strSql.Append(" where TABLE_ID in ("+TABLE_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DQYT.HTDZ.Model.BDDATATABLEModel GetModel(decimal TABLE_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select TABLE_ID,TABLE_CODE,TABLE_NAME,DESCTRIPTION from BDDATATABLE ");
			strSql.Append(" where TABLE_ID=:TABLE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,22)			};
			parameters[0].Value = TABLE_ID;

			DQYT.HTDZ.Model.BDDATATABLEModel model=new DQYT.HTDZ.Model.BDDATATABLEModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DQYT.HTDZ.Model.BDDATATABLEModel DataRowToModel(DataRow row)
		{
			DQYT.HTDZ.Model.BDDATATABLEModel model=new DQYT.HTDZ.Model.BDDATATABLEModel();
			if (row != null)
			{
				if(row["TABLE_ID"]!=null && row["TABLE_ID"].ToString()!="")
				{
					model.TABLE_ID=decimal.Parse(row["TABLE_ID"].ToString());
				}
				if(row["TABLE_CODE"]!=null)
				{
					model.TABLE_CODE=row["TABLE_CODE"].ToString();
				}
				if(row["TABLE_NAME"]!=null)
				{
					model.TABLE_NAME=row["TABLE_NAME"].ToString();
				}
				if(row["DESCTRIPTION"]!=null)
				{
					model.DESCTRIPTION=row["DESCTRIPTION"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select TABLE_ID,TABLE_CODE,TABLE_NAME,DESCTRIPTION ");
			strSql.Append(" FROM BDDATATABLE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
           
			return DbHelperOra.Query(strSql.ToString());
		}
        

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDDATATABLE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.TABLE_ID desc");
			}
			strSql.Append(")AS Row, T.*  from BDDATATABLE T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDDATATABLE";
			parameters[1].Value = "TABLE_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

